<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:XSWeekDetails="http://rpmestre.net/xscrawler">
	<xsl:namespace-alias stylesheet-prefix="XSWeekDetails" result-prefix="xsl"/>
	<xsl:output method="html" indent="yes"/>
	<xsl:template match="/">
		<html>
			<head>
				<title>XpertStats XSCrawler - Jornadas Liga Zon Sagres</title>
				<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
				<link rel="shortcut icon" href="../imagens/template/logo.ico"/>
				<link rel="icon" type="image/gif" href="../imagens/template/logo.ico"/>
				<script language="JavaScript" src="../calendario.js"/>
				<link href="../style.css" rel="stylesheet" type="text/css"/>
				<link href="../style2.css" rel="stylesheet" type="text/css"/>
				<link href="../menubuttons.css" rel="stylesheet" type="text/css"/>
				<link href="../menu.css" rel="stylesheet" type="text/css"/>
				<link href="../fbstyle.css" rel="stylesheet" type="text/css"/>
			</head>
			<body>
				<div id="wrap">
					<div id="header">
						<div id="headerH">
							<div id="logo">
								<a href="index.php">
									<img src="../imagens/template/logo.png"/>
								</a>
							</div>
						</div>
					</div>
					<div id="menuD">
						<div id="menuB">
							<div id="menu">
								<a class="active">
									<span>XSCRAWLER MENU</span>
								</a>
								<a href="../index.php">
									<span>Home</span>
								</a>
								<a href="/xscrawler/xsweeks.php">
									<span>Actualizar Resultados</span>
								</a>
							</div>
						</div>
					</div>
					<div id="main-col" style="padding-top:10px;">
						<h2 style="padding-bottom:10px">Actualização de Resultados</h2>
						<div class="roundsection" style="width: 800px; padding:10px;">
							<xsl:variable name="weekId" select="XSWeekDetails:XSWeekDetails/@weekID"/>
							<xsl:variable name="hasScore" select="boolean(document(string(concat('../weekCache/', $weekId, '.xml'))))"/>
							<xsl:variable name="weekDescription" select="XSWeekDetails:weekDescription"/>
							<xsl:choose>
								<xsl:when test="$hasScore">
									<h3 align="center">Jogos <xsl:value-of select="substring-after($weekId,'_')"/>ª jornada </h3>
									<xsl:for-each select="XSWeekDetails:XSWeekDetails/XSWeekDetails:match">
										<table align="center" class="simpletable" style="margin-top:50px;">
											<xsl:variable name="hostId" select="XSWeekDetails:host/@id"/>
											<xsl:variable name="visitorId" select="XSWeekDetails:visitor/@id"/>
											<xsl:variable name="tMatch" select="document(string(concat('../weekCache/', $weekId, '.xml')))/ZZMatches[@weekID=$weekId]/game[home_team/xs_id/@id=$hostId and visitor_team/xs_id/@id=$visitorId]"/>
											<thead>
												<tr style="line-height:35px">
													<th width="35%" style="font-size:14px">
														<xsl:value-of select="XSWeekDetails:host"/>
													</th>
													<th width="10%" style="font-size:20px">
														<xsl:value-of select="$tMatch/score/home"/>
													</th>
													<th width="10%">X</th>
													<th width="10%" style="font-size:20px">
														<xsl:value-of select="$tMatch/score/visitor"/>
													</th>
													<th width="35%" style="font-size:14px">
														<xsl:value-of select="XSWeekDetails:visitor"/>
													</th>
												</tr>
											</thead>
											<tbody>
												<tr>
													<td colspan="5" align="center">
														<xsl:value-of select="$tMatch/date"/>
													</td>
												</tr>
												<tr>
													<td colspan="5" align="center">
														<xsl:value-of select="$tMatch/stadium"/>
													</td>
												</tr>
												<tr>
													<td colspan="5" align="center">
														<xsl:value-of select="$tMatch/referee"/>
													</td>
												</tr>
												<tr>
													<td colspan="5" align="center" style="font-size:14px; font-weight:bold">Golos</td>
												</tr>
												<xsl:for-each select="$tMatch/descendant::*//player[count(goals/minute)>0]/goals">
												<xsl:sort select="minute"/>
													<tr><td/>
														<td align="right"><xsl:value-of select="parent::node()/number"/></td>
														<td><xsl:value-of select="parent::node()/name"/></td>
														<td colspan="2">
															<xsl:for-each select="minute">
																<xsl:value-of select="."/>'
															</xsl:for-each>
														</td>
													</tr>
												</xsl:for-each>
											</tbody>
										</table>
									</xsl:for-each>
								</xsl:when>
								<xsl:otherwise>
									<div style="padding:20px; background-color:#f66; font-size:14px; border: 3px solid #C66; text-align:center">Não existem resultados retirados para esta jornada. Tente o 
								  	<a href="ZZ_upgrade.php">UPGRADE</a>.</div>
									<table align="center">
										<thead>
											<tr>
												<th colspan="3"><h4 style="text-align:center; padding-top:20px">Jogos <xsl:value-of select="substring-after($weekId,'_')"/>ª jornada </h4></th>
											</tr>
										</thead>
										<tbody>

									<xsl:for-each select="XSWeekDetails:XSWeekDetails/XSWeekDetails:match">
										<tr>
											<td style="text-align:right"><xsl:value-of select="XSWeekDetails:host" /></td>
											<td>x</td>
											<td><xsl:value-of select="XSWeekDetails:visitor" /></td>
										</tr>
									</xsl:for-each>
									
										</tbody>
									</table>
									
									
								</xsl:otherwise>
							</xsl:choose>
						</div>
					</div>
				</div>
				<div id="footer">
					<div id="footerD">
						<div id="footerF" class="aligned">
					</div>
						<div id="footerS" class="aligned">XS v1.4 Lite</div>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>
